﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SecureCookie.Implementation.Helper;
using System.Configuration;

namespace SecureCookie.Implementation.UnitTest.HelperTests
{
    /// <summary>
    /// </summary>
    [TestClass]
    public class ExceptionHelperTests
    {
        /// <summary>
        /// </summary>
        [TestMethod]
        public void Test_RepresentAsStringRecursively()
        {
            var innerOne = new ApplicationException("Woehoew");
            innerOne.Data["TestKey"] = "Ola Pola";
            var innerTwo = new NullReferenceException("Boogy", innerOne);
            innerOne.Data["Elvis"] = "Presley";
            var exception = new ConfigurationErrorsException("top exception", innerTwo);
            exception.Data["Nick"] = "Jagger";

            try
            {
                throw exception;
            }
            catch (ConfigurationErrorsException ex)
            {
                var result = ex.RepresentAsStringRecursively();

                Assert.IsTrue(result.Contains("Woehoew"));
                Assert.IsTrue(result.Contains("TestKey"));
                Assert.IsTrue(result.Contains("Ola Pola"));
                Assert.IsTrue(result.Contains("Elvis"));
                Assert.IsTrue(result.Contains("Presley"));
                Assert.IsTrue(result.Contains("Nick"));
                Assert.IsTrue(result.Contains("Jagger"));
                Assert.IsTrue(result.Contains("Boogy"));
                Assert.IsTrue(result.Contains("Test_RepresentAsStringRecursively"));
            }

        }
    }
}
